﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using JobHunter.Model.Entity;

namespace JobHunter.Model.Repository
{
	public class EmployerRepository
	{
		private MyDbContext _context = null;

		public EmployerRepository()
		{
			_context = new MyDbContext();
		}

		public void Save(Employer employer)
		{
			if (_context.Employers.All(e => e.Name != employer.Name))
			{
				_context.Employers.Add(employer);
				_context.SaveChanges();
			}
		}

		public IEnumerable<Employer> Get(Func<Employer, bool> func)
		{
			return _context.Employers.Where(func);
		}

		public void Save(IList<Employer> employers)
		{
			foreach (var employer in employers)
			{
				if (_context.Employers.All(e => e.Name != employer.Name))
					_context.Employers.Add(employer);
			}
			_context.SaveChanges();
		}
	}
}
